package cn.ren.hai.base.service.impl;

import cn.ren.hai.base.entity.RhTable;
import cn.ren.hai.base.entity.RhTableField;
import cn.ren.hai.base.mapper.RhTableMapper;
import cn.ren.hai.base.service.RhTableFieldService;
import cn.ren.hai.base.service.RhTableService;
import cn.ren.hai.core.entity.PageInfo;
import cn.ren.hai.core.entity.QueryPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 导航  服务实现类
 * </p>
 *
 * @author wangdao
 * @since 2021-06-09
 */
@Service
public class RhTableServiceImpl extends ServiceImpl<RhTableMapper, RhTable> implements RhTableService {

    private final RhTableMapper rhTableMapper;

    private final RhTableFieldService rhTableFieldService;

    public RhTableServiceImpl(RhTableMapper rhTableMapper, RhTableFieldService rhTableFieldService) {
        this.rhTableMapper = rhTableMapper;
        this.rhTableFieldService = rhTableFieldService;
    }

    @Override
    public PageInfo<RhTable> list(QueryPage<RhTable> page) {
        QueryWrapper<RhTable> queryWrapper = new QueryWrapper<>();
        page.startPage();
        return new PageInfo<>(rhTableMapper.selectList(queryWrapper));
    }

    @Override
    public RhTable getByTableName(String name) {
        QueryWrapper<RhTable> rhTableQueryWrapper = new QueryWrapper<>();
        rhTableQueryWrapper.lambda().eq(RhTable::getName, name);
        RhTable rhTable = rhTableMapper.selectOne(rhTableQueryWrapper);
        rhTable.setFields(rhTableFieldService.list(new QueryWrapper<RhTableField>().lambda().eq(RhTableField::getTableId,rhTable.getId())));
        return rhTable;
    }
}
